﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.View.Feiyong
{
    /// <summary>
    /// Elec.xaml 的交互逻辑
    /// </summary>
    public partial class Gas : Page
    {

        ViewModel.CostViewModel vm;
        Model.DataContext dbContext = new Model.DataContext();
        public Gas()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.CostViewModel;

            vm.MeterType = "天然气";
            vm.ListWater = new List<Model.F_Water>();
            LoadData();
        }
        Model.DataContext context = new Model.DataContext();
        public void LoadData()
        {
            vm.ListWater = context.DB.Queryable<Model.F_Water>().Where(w => w.MeterType == vm.MeterType).ToList();

            var buildList = context.DB.Queryable<Model.Building>().ToList();
            cmb_Build.ItemsSource = buildList;
            cmb_Build.SelectedValuePath = "Id";
            cmb_Build.DisplayMemberPath = "Name";
        }

        private void Btn_Query_Click(object sender, RoutedEventArgs e)
        {

            vm.Query(cmb_Build.SelectedValue.ToString(), txt_roomNo.Text, txt_OwnerName.Text);

        }

        private void Btn_JiaoFei_Click(object sender, RoutedEventArgs e)
        {
            if(vm.CurrWater.IsCharged ==false)
            {
                //查询费用
                vm.PayAmount = ((decimal)vm.CurrWater.CurDegrees - (decimal)vm.CurrWater.PreDegrees) * vm.CurrWater.Price;

                vm.Dialog = HandyControl.Controls.Dialog.Show(new Part.Pay());
            }
            else
            {
                HandyControl.Controls.Growl.WarningGlobal("该单已收费！");
            }
            
           
    }
    }
}
